<?php 
namespace Home\Controller;
use Hdphp\Library\Controller;


Class RegisterController extends Controller{
	//注册方法
	Public function register(){
		if(!IS_POST) halt('非法访问');
		if( $_SESSION['code'] !=strtoupper($_POST['verify']) ){
			$this->error('验证码错误','./index.php');
		}

		if( $_POST['pwd'] != $_POST['pwded'] ){
			$this->error('两次密码不一致','./index.php');
		}

		$username=htmlspecialchars($_POST['username']);
		$sql="SELECT * FROM hd_user where username = '{$username}' ";
		if( M()->query($sql) ){
			$this->error('用户名存在','./index.php');
		}

		$pwd=md5($_POST['pwd']);
		$restime=time();
		$loginip=$_SERVER['REMOTE_ADDR'];

		$sql="INSERT INTO hd_user SET username='{$username}',passwd='{$pwd}',restime={$restime},logintime={$restime},loginip='{$loginip}' ";
		if( $id= M()->exec($sql) ){
			$_SESSION['username']=$username;
			$_SESSION['uid']=$id;
			$this->success('注册成功','./index.php');
		}else{
			$this->error('注册失败','./index.php');
		}


	}

	//验证码
	public function code(){
		$code =new \Hdphp\Tool\code(4,99,35,null,18);
		$code->show();
	}


}

 ?>